<?php
namespace app\manage\model;

use think\Model;

class Config extends Model
{
  public function saveConfig($data)
  {
    if(empty($data) || !is_array($data)){
      return false;
    }
    foreach($data as $key => $value){
      if(empty($key)){
        continue;//结束本次循环
      }
      Config::where('config_varname',$key)->update(['config_value'=>trim($value)]);
    }

    $configInfo = $this->select();
    $_br = "\r\n";
		$_tab = "\t";
		$_profile = '<?php'.$_br;
    $_profile .= 'return ['.$_br;
    foreach ($configInfo as $key => $value) {
      $_profile .= "\t'".$value['config_varname']."'=>'".$value['config_value']."',\n";
    }
    $_profile .= '];'.$_br;
		$_profile .= '?>'.$_br;
    if(file_put_contents(ROOT_PATH.'/application/extra/setting.php',$_profile)){
			return true;
		}else{
      return false;
    }
  }
}
